/****************************************************
	文件：UTimer.cs
	作者：HuskyT
	邮箱：1005240602@qq.com
	日期：2020/10/11 11:35:22
	功能：计时器管理器
*****************************************************/

using System;

namespace HTUtility
{
    public class UTimer : Singleton<UTimer>
    {
        #region 字段
        private HTTimer mHTTimer;
        #endregion

        #region 初始化
        /// <summary>
        /// 初始化计时器
        /// </summary>
        public void Init()
        {
            //初始化HTTimer
            mHTTimer = new HTTimer();
            //设置打印日志接口
            mHTTimer.SetLog((msg) =>
            {
                HTLogger.Debug(msg);
            });

            HTLogger.Debug("HTTimer init done.");
        }
        /// <summary>
        /// HTTimer 的帧函数
        /// </summary>
        public void OnUpdate()
        {
            mHTTimer.Update();
        }
        /// <summary>
        /// 重置计时器
        /// </summary>
        public void Reset()
        {
            mHTTimer.Reset();
        }
        #endregion

        #region 计时任务
        /// <summary>
        /// 添加计时任务
        /// 返回此任务的全局ID
        /// </summary>
        /// <param 计时任务回调="callBack"></param>
        /// <param 延迟时间="delayTime"></param>
        /// <param 时间单位="timeUnit"></param>
        /// <param 循环次数="loopCount"></param>
        /// <returns></returns>
        public int AddTimeTask(Action<int> callBack, double delayTime, TimeUnit timeUnit = TimeUnit.MilliSecond, int loopCount = 1)
        {
            return mHTTimer.AddTimeTask(callBack, delayTime, timeUnit, loopCount);
        }
        /// <summary>
        /// 移除计时任务
        /// </summary>
        /// <param 任务的全局ID="tID"></param>
        public void RemoveTimeTask(int tID)
        {
            mHTTimer.RemoveTimeTask(tID);
        }
        /// <summary>
        /// 替换计时任务
        /// 返回bool（是否替换成功）
        /// </summary>
        /// <param 待替换任务的全局ID="tID"></param>
        /// <param 计时任务回调="callBack"></param>
        /// <param 延迟时间="delayTime"></param>
        /// <param 时间单位="timeUnit"></param>
        /// <param 循环次数="loopCount"></param>
        /// <returns></returns>
        public bool ReplaceTimeTask(int tID, Action<int> callBack, double delayTime, TimeUnit timeUnit = TimeUnit.MilliSecond, int loopCount = 1)
        {
            return mHTTimer.ReplaceTimeTask(tID, callBack, delayTime, timeUnit, loopCount);
        }
        #endregion

        #region 帧任务
        /// <summary>
        /// 添加帧任务
        /// 返回此任务的全局ID
        /// </summary>
        /// <param 帧任务回调="callBack"></param>
        /// <param 延迟帧="delayFrame"></param>
        /// <param 循环次数="loopCount"></param>
        /// <returns></returns>
        public int AddFrameTask(Action<int> callBack, int delayFrame, int loopCount = 1)
        {
            return mHTTimer.AddFrameTask(callBack, delayFrame, loopCount);
        }
        /// <summary>
        /// 删除帧任务
        /// </summary>
        /// <param 任务的全局ID="tID"></param>
        public void DeleteFrameTask(int tID)
        {
            mHTTimer.DeleteFrameTask(tID);
        }
        /// <summary>
        /// 替换帧任务
        /// 返回bool（是否替换成功）
        /// </summary>
        /// <param 待替换任务的全局ID="tID"></param>
        /// <param 帧任务回调="callBack"></param>
        /// <param 延迟帧="delayFrame"></param>
        /// <param 循环次数="loopCount"></param>
        /// <returns></returns>
        public bool ReplaceFrameTask(int tID, Action<int> callBack, int delayFrame, int loopCount = 1)
        {
            return mHTTimer.ReplaceFrameTask(tID, callBack, delayFrame, loopCount);
        }
        #endregion
    }
}
